import AbstractRuntimeView from "../../../common/abstract/mvc/AbstractRuntimeView";
import { soundMgr } from "../../../common/def/sound";
import Event from "../../../common/manager/EventClick";
import { ZYEventMgr } from "../../../common/manager/YLEventMgr";
import gameModel from "../../../common/model/gameModel";
import { SdkEventModel } from "../../../common/model/SdkEventModel";

/**
 * 
 * @author: xj.huang
 * @date: 2021/08/02 10:18:11
 */
export default class GameView extends AbstractRuntimeView<null, null> {
    private GameTwoSIde: Laya.Image;
    private GuideBox: Laya.Box;
    private MusicBtn: Laya.Image;
    private SetBtn: Laya.Image;
    private AudioBtn: Laya.Image;
    private ani2: Laya.FrameAnimation;
    private clickBg: Laya.Image;
    private soundNot = false;
    private musicNot = false;
    constructor() {
        super()
    }
    onOnce() {
        this.GameTwoSIde.visible = false;
        this.ani2.index = 0
        Event.onClick(this.SetBtn, this, this.onShowSoundBtn);
        Event.onClick(this.AudioBtn, this, this.onSetSound);
        Event.onClick(this.MusicBtn, this, this.onSetBGM);
        Event.onClick(this.clickBg, this, this.onStartGame);
        ZYEventMgr.on(GameEvent.GAME2SDK_OVER_SUCCESS, this, this.onResetMode);
    }
    onStartGame() {
        SdkEventModel.onPlayGame()
        this.GuideBox.visible = false;
        this.clickBg.visible = false
    }
    onResetMode() {
        this.GuideBox.visible = true;
        this.clickBg.visible = true;
    }
    onShowSoundBtn() {
        if (this.ani2.index === 0) {
            this.ani2.wrapMode = 0
            this.ani2.play(0, false);
        }
        if (this.ani2.index == 13) {
            this.ani2.wrapMode = 1
            this.ani2.play(this.ani2.index, false);
        }
    }
    onSetSound() {
        if (this.soundNot) {
            this.AudioBtn.skin = "ZhiYingRes/GameUI/GameUI/ylk-on.png";
            this.soundNot = false;
        } else {
            this.AudioBtn.skin = "ZhiYingRes/GameUI/GameUI/ylk-off.png"
            this.soundNot = true;
        }
        soundMgr.isMuteSound = this.soundNot
    }
    onSetBGM() {
        if (this.musicNot) {
            this.MusicBtn.skin = "ZhiYingRes/GameUI/GameUI/yinx-on.png"
            this.musicNot = false;
        } else {
            this.MusicBtn.skin = "ZhiYingRes/GameUI/GameUI/yinx-off.png"
            this.musicNot = true;
        }
        soundMgr.isMuteMusic = this.musicNot
    }
    onSDKSet() {
        if (gameModel.userData.hasMusic) {
            this.MusicBtn.skin = "ZhiYingRes/GameUI/GameUI/yinx-on.png"
            this.musicNot = false;
        } else {
            this.MusicBtn.skin = "ZhiYingRes/GameUI/GameUI/yinx-off.png"
            this.musicNot = true;
        }
        soundMgr.isMuteMusic = gameModel.userData.hasMusic;
        if (gameModel.userData.hasSound) {
            this.AudioBtn.skin = "ZhiYingRes/GameUI/GameUI/ylk-on.png";
            this.soundNot = false;
        } else {
            this.AudioBtn.skin = "ZhiYingRes/GameUI/GameUI/ylk-off.png"
            this.soundNot = true;
        }
        soundMgr.isMuteSound = gameModel.userData.hasSound
    }
}